<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Netty WebSocket服务器</title>
</head>
<body>
<script type="text/javascript">
	var socket;
	if(!window.WebSocket) {
		window.WebSocket = window.MozWebSocket;
	}
	if(window.WebSocket) {
		socket = new WebSocket("http://localhost:8080/websocket");
		socket.onmessgae = function(event){
			var ta = document.getElementById("responseText");
			ta.value = "";
			ta.value = event.data;
		};
		socket.onopen = function(event) {
			var ta = document.getElementById("responseText");
			ta.value = "打开WebSocket服务正常，浏览器支持WebSocket！";
		};
		socket.onclose = function(event) {
			var ta = document.getElementById("responseText");
			ta.value = "";
			ta.value = "WebSocket关闭！";
		}
	} else {
		alert("抱歉，您的浏览器不支持WebSocket协议！");
	}
	
	function send(message) {
		if(!window.WebSocket) {return;}
		if(socket.readyState = WebSocket.OPEN) {
			socket.send(message);
		} else {
			alert("WebSocket连接没有建立成功！");
		}
	}
	
</script>

	<form onsubmit="return false;">
		<input type="text" name="message" value="Netty WebSocket Test!" />
		<br/>
		<br/>
		<input type="submit" value="发送请求" onclick="send(this.form.message.value)">
		
		<hr color="blue">
		<h3>服务器响应：</h3>
		<textarea id="responseText" style="width: 500px;heigh: 300px;"></textarea>
	</form>

</body>
</html>